<?php

/**
 * 餐厅编辑post
 * 
 * @copyright xinwei
 * @since 2012-04-17
 */


include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");

include_once($_SERVER["DOCUMENT_ROOT"] . "/include/user/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/mblog/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/tuijian/inc.php");
$g_cgival = array();
$g_pro = array();
$g_show = array();

function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	//check refer  -  add by xinwei
	if(! security_check::check_refer())
	{
		throw new Exception("来路不明");
	}
	
	
	cgi::both($g_cgival["id"], "id", 0);
	$g_cgival["id"] = intval($g_cgival["id"]);
	
	
	cgi::both($g_cgival["uid"], "uid", "");
	$g_cgival["uid"] = string::un_html($g_cgival["uid"]);
	
	cgi::both($g_cgival["topic_id"], "topic_id", "");
	$g_cgival["topic_id"] = string::un_html($g_cgival["topic_id"]);
	
	cgi::both($g_cgival["status"], "status", "");
	$g_cgival["status"] = string::un_html($g_cgival["status"]);
	
	cgi::both($g_cgival["type"], "type", "add");

	
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show,$config;
	
	$id = $g_cgival["id"];	
	$uid = $g_cgival["uid"];
	$topic_id = $g_cgival["topic_id"];
	$status = $g_cgival["status"];
	
	if($g_cgival["type"] == "add")
	{
		if($id)
		{
		
			$db_user_fans_for_search = new db_user_fans_for_search();
			$db_tuijian_jiaodian = new db_tuijian_jiaodian();
			$db_user_fans_for_search->admin_update_by_id($id,$status,$uid,$topic_id);
			
			echo "<script>alert('操作成功');location.href='user_fans_for_search_list.php';</script>";
		}
		else
		{
			
			
			$db_user_fans_for_search = new db_user_fans_for_search();
			
			$res = $db_user_fans_for_search->admin_insert_user_fans_for_search($uid,$topic_id);
			if(!$res)
			{
				echo "数据库操作失败！";
				exit;
			}
			
			echo "<script>alert('操作成功');location.href='user_fans_for_search_list.php';</script>";
		
		}
			
	}
	elseif($g_cgival["type"] == "del")
	{
		$db_user_fans_for_search = new db_user_fans_for_search();
		$res = $db_user_fans_for_search->admin_update_by_id($id,0);
		if(!$res)
		{
			throw new Exception("数据库操作失败！");
		}
	}
	elseif($g_cgival["type"] == "undel")
	{
		$db_user_fans_for_search = new db_user_fans_for_search();
		$res = $db_user_fans_for_search->admin_update_by_id($id,1);
		if(!$res)
		{
			throw new Exception("数据库操作失败！");
		}
	}
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album_list.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
	{
		print_r($g_show);
		exit;
	}
	
	
	echo json_encode($g_show);
}

